<?php
/**
 *      [Elitechmedia!] (C)2001-2099 MYSELF Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: addimg.php 22609 2013-10-16 01:55:33Z zhangchaofeng
 */
if(!isset($_SESSION)){
	session_start();
}
if(!$_SESSION['uid']){
	require_once "tmp/login.htm";exit;
}
include_once("classes/DB.class.php");
include_once("function/member.php");
include_once("function/function_file.php");
include_once("function/util.func.php");
date_default_timezone_set('Asia/Shanghai');
$id=$_REQUEST['id'];
if($id!=''):
$info = $GLOBALS["DB"]->result("SELECT id,path,title,e_title,name,descinfo,e_descinfo FROM img where id='$id'");
$info=$info[0];
endif;
if($_SERVER['REQUEST_METHOD'] == 'POST'):
	$upid=$_POST['upid'];
	$path=realpath(dirname('static'));
	$up_dir_file=$path."/static/upload/";//上传目录路径
	if (!file_exists($up_dir_file)):
		if(!mkdirs($up_dir_file,0777)):
			$message="<font color='red'>对不起您没有权限创建文件夹...!</font>";
			$text="如果您的浏览器没有自动跳转，请点击这里";
			$url='image.php';
			include 'tmp/error.htm';exit;
		endif;
	endif;
	if(isset($_FILES["pic"]) && !empty($_FILES["pic"]['name'])):
		//创建新名称
		$newname = time().'.'.array_pop(explode('.',$_FILES['pic']['name']));
		//上传文件
		$e_pic_message=uploadPic('pic',$up_dir_file,$newname);
		if(empty($e_pic_message)):
			$data['name']=$newname;
		else:
			$message="<font color='red'>图片上传失败：$errorpic</font>";
			$text="如果您的浏览器没有自动跳转，请点击这里";
			$url='image.php';
			include 'tmp/error.htm';exit;
		endif;
	endif;
	$data['title']=addslashes($_POST['title']);
	$data['e_title']=addslashes($_POST['e_title']);
	$data['descinfo']=addslashes($_POST['descinfo']);
	$data['e_descinfo']=addslashes($_POST['e_descinfo']);
	$data['path']=$up_dir_file;//简介
	$data['createdate']=time();//简介
	if($upid==''):
		$fid = $GLOBALS["DB"]->execute_event("INSERT INTO img set ".implode_field_value($data));
		if(!$fid):
		$message="<font color='red'>对不起数据保存失败.!!</font>";
		$text="如果您的浏览器没有自动跳转，请点击这里";
		$url='image.php';
		include 'tmp/error.htm';exit;
		else:
		$message="<font color='green'>您的操作已经成功....</font>";
		$text="如果您的浏览器没有自动跳转，请点击这里";
		$url='image.php';
		include 'tmp/success.htm';exit;
		endif;
	else:
		$GLOBALS["DB"]->execute_event("update img set ".implode_field_value($data) ." where id='$upid'");
		$message="<font color='green'>您的操作已经成功....</font>";
		$text="如果您的浏览器没有自动跳转，请点击这里";
		$url='image.php';
		include 'tmp/success.htm';exit;
	endif;
endif;
include 'tmp/addimg.htm';